
#include <bits/stdc++.h>
using namespace std;
int locks[100005];

int main() {
  int n, l = 0, r = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> locks[i];
  }
  for (int i = 1; i <= n; i++) {
    if (locks[i] == 1) {
      l = i;
      break;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (locks[i] == 1) {
      r = i;
      break;
    }
  }

  cout << r - l << endl;

  return 0;
}